Comments (6)
Pyright (the type checker upon which pylance is built) is working correctly here. This isn't a bug.
You have defined two instance methods get_bar
and get_a_bar
. Instance methods must have a self
parameter. If your intent is for these to be static methods, you should add a @staticmethod
decorator.
@staticmethod
def get_bar() -> bar:
return foo.bar()
@staticmethod
def get_a_bar(a: int = 3) -> bar:
return foo.bar(a=a)
from pylance-release.
@erictraut
I understand. However, in my case, I will never instantiate the foo
class. Therefore, it's acceptable to call get_a_bar()
as foo.get_a_bar()
without using the @staticmethod
decorator.
More importantly, in the previous version of Pylance (or Pyright?), this approach worked just fine.
from pylance-release.
If you want a static type analyzer to understand your code, you will need to decorate these as @staticmethod
.
The recent changes were made to increase pyright's conformance to the typing spec. The new behavior is correct, and we don't have plans to revert to the old (non-conformant) behavior.
from pylance-release.
@erictraut
If this behavior is expected, I still believe it is non-conformant.
At least in my opinion, these type hints should either not function at all, or work perfectly. But not partially working.
This means:
test1
should not be hinted as abar()
object.- Neither
foo.get_bar()
norfoo.get_a_bar()
should hint their return type as abar()
object.
Alternatively,
test2
should be hinted as abar()
object, which is what I expect.
from pylance-release.
Add a @staticmethod
decorator if you want this to work with pyright.
from pylance-release.
@erictraut
We should not merely avoid triggering bugs as a solution; instead, we should address and resolve the underlying issues that cause the bugs, right?
from pylance-release.
Related Issues (20)
- `Import could not be resolved` with `[tool.setuptools.package-dir]` HOT 15
- Pylance reports import Missing in inexistent file when git enabled HOT 21
- Pylance still report problems in excluded or ignored directories, even in a closed file HOT 8
- Report HOT 1
- Pylance 2024.5.1 and 2024.4.1 crashes regularly, reverting back to 2024.3.2 runs stable HOT 8
- ReportUnnecessaryComparison False Positive HOT 1
- Warnings for unbound variables? HOT 3
- Cell magics disable parsing of python code HOT 8
- "Go to definition" does not work when the method is in the parent class HOT 1
- Consecutive comment lines are not foldable in Python but are in (at least some) other languages HOT 1
- Pylance makes type hints in Python unusable for me HOT 14
- `"python.analysis.autoImportCompletions": false` not working. HOT 1
- Syntax highlighting issue for a valid conditional logic when type hints provided HOT 3
- PyLance crashes when setting node option '--no-deprecation' HOT 24
- My VSCode keep freezing because of Pylance HOT 1
- pylance bug HOT 1
- F2 renaming not working across all python files HOT 2
- Better string completions HOT 1
- import side by side in standalone file didn't work HOT 1
- Problema com desempenho HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylance-release.