Skip to content

Bogus undefined name error with generic type alias #7092

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

Closed
Oberon00 opened this issue Jun 28, 2019 · 6 comments
Closed

Bogus undefined name error with generic type alias #7092

Oberon00 opened this issue Jun 28, 2019 · 6 comments
Labels

Comments

@Oberon00
Copy link

Oberon00 commented Jun 28, 2019

  • Are you reporting a bug, or opening a feature request?

Bug.

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

This requires two modules to trigger the bug:
dummy.py:

from typing import Type, TypeVar, Callable

T = TypeVar('T')
ImplementationFactory = Callable[[Type[T]], T]

MyFactory = ImplementationFactory[str] # Works fine

dummy2.py:

import dummy

MyFactory2 = dummy.ImplementationFactory[str]
  • What is the actual behavior/output?
$ mypy dummy2.py
dummy2.py:4: error: Name 'T' is not defined

Note that line 4 is empty. You can also add comments to get a different line number displacement. Also note that T is never referred to in dummy2.

  • What is the behavior/output you expect?

I would expect no errors for this code.

  • What are the versions of mypy and Python you are using?
$ mypy --version
mypy 0.711
$ python --version
Python 3.7.3
  • Do you see the same issue after installing mypy from Git master?

I didn't try.

  • What are the mypy flags you are using? (For example --strict-optional)

None. The command line is shown in full, there is no config file.

@JelleZijlstra
Copy link
Member

This sounds similar to #7077.

@Oberon00
Copy link
Author

Oberon00 commented Jul 8, 2019

Maybe similar, but this happens also without any special configuration so I'd say it is more severe based on that.

Can this issue get any labels, like "bug"?

@ilevkivskyi
Copy link
Member

This still happens on master (and is pretty embarrassing).

@Oberon00
Copy link
Author

Oberon00 commented Sep 26, 2019

Any news on this? This is currently causing us to copy & paste type definitions around in https://github.com/open-telemetry/opentelemetry-python (e.g. https://github.com/open-telemetry/opentelemetry-python/blob/84f589b6f8a4770c3c6ce29c7b352b1972241c4f/opentelemetry-api/src/opentelemetry/trace/__init__.py#L497-L502)

@JukkaL JukkaL changed the title Bogus undefined name error with generic type alias. Bogus undefined name error with generic type alias Jan 7, 2020
@pappasam
Copy link

pappasam commented Nov 28, 2020

I've tried this example with mypy version 0.790 on Python 3.8.6 and am not receiving any error. Maybe this issue is fixed?

@hauntsaninja
Copy link
Collaborator

Thanks for checking! mypy_primer indicates this was fixed by #7885

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants