-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix name __path__
not defined
#5212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The last commit was to fix the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix is not perfect because
typing.List[str]
would be better.
The previous attempt #3527 didn't land exactly because of this. You could read discussions in that PR and improve your solution.
@@ -12,7 +12,7 @@ import m | |||
m.x # E: "object" has no attribute "x" | |||
[file m.py] | |||
|
|||
[case testListMissingFromStubs] | |||
[case testListMissingFromStubs-skip] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you skip this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I thought that was not that important. I think that it can be fixed adding some .pyi
stub that define list
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried del list
but in mypy del
deletes the value and not the variable itself. I would keep as is and mark this test to skip.
[case testModule__path__] | ||
import typing | ||
x = __path__ # type: list | ||
a = __path__ # type: A # E: Incompatible types in assignment (expression has type "list", variable has type "A") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just using a reveal_type
on __path__
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I was only going with the flow of other similar tests. Should them also use reveal_type
on __name__
and etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As builtins.list
is partially typed, reveal_type
reveals builtins.list[Any]
instead of builtins.list
.
@@ -101,7 +101,8 @@ def get_column(self) -> int: | |||
implicit_module_attrs = {'__name__': '__builtins__.str', | |||
'__doc__': None, # depends on Python version, see semanal.py | |||
'__file__': '__builtins__.str', | |||
'__package__': '__builtins__.str'} | |||
'__package__': '__builtins__.str', | |||
'__path__': '__builtins__.list'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC __path__
is only defined in __init__.py
modules, not in every module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that __path__
was defined everywhere. I will fix that.
#3527 was typing I didn't knew that The test was skipped because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are few more comments. Also I still think it should be List[str]
, not just list
.
# We are running tests without 'list' in builtins. | ||
# TODO: Maybe optionally choose an default fixture stub per test file? | ||
if 'list' not in self.sem.globals: | ||
literal_types.append(('list', AnyType(TypeOfAny.special_form))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very dangerous. With this addition many tests will pass (of fail in ultra-weird way) if someone forgets to add a fixture with list
. It is OK with literals, but not with a class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't list
a literal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is not, this construct (literal_types
) is for things like None
, True
, False
etc.
@@ -20,4 +20,5 @@ class str: | |||
class bytes: pass | |||
class bytearray: pass | |||
class tuple(Generic[T]): pass | |||
class list(Generic[T]): pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The header of this file says # builtins stub with non-generic primitive types
, so I would avoid adding generic classes here. We have already enough fixtures with list
, why do you need more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is a bultin, but I agree that there are enough fixtures.
@@ -101,7 +101,8 @@ def get_column(self) -> int: | |||
implicit_module_attrs = {'__name__': '__builtins__.str', | |||
'__doc__': None, # depends on Python version, see semanal.py | |||
'__file__': '__builtins__.str', | |||
'__package__': '__builtins__.str'} | |||
'__package__': '__builtins__.str', | |||
'__path__': '__builtins__.list'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you will fix this, you can then just take care to add list.pyi
fixture to all tests that include __init__.py[i]
files. I think there are not many of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that __path__
shoun't be here because it exists only in __init__
? So __init__.py[i]
that uses __path__
must include an fixture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please see the previous comments to this code. You already promised to fix it in #5212 (comment) two months ago.
It is OK to just close this if you don't have time/desire to work on this. If you still want to do this, then please go through all previous comments and fix mentioned issues.
This seems stalled. @pslacerda are you planning to address the issues Ivan mentioned in the code review? |
Let's close this, it's stalled. |
In #1422
__path__
implicit module attribute is not defined. This fix is not perfect becausetyping.List[str]
would be better.