Skip to content
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

Allow typing and still trigger by hash and eq #39

Merged
merged 17 commits into from
Jun 2, 2023
Merged

Conversation

Mandera
Copy link
Contributor

@Mandera Mandera commented May 20, 2023

Closes #30
Closes #31

An experiment, might work.
The idea is to make FakeModule hashable only if typing module is in the call stack.

Possibly the best of both worlds.
Questionable implementation.
Clean up if proceeding!

@ZanSara
Copy link
Contributor

ZanSara commented May 22, 2023

Wow! This is some serious black magic, but if that gives us typing and triggers on __eq__ and __hash__ we should go for it! Thanks for the help on this issue 😊

@Mandera
Copy link
Contributor Author

Mandera commented Jun 2, 2023

Got a pretty clean implementation for the dynamic dunders now!
I want to make the _inside_typing() function better, the venv structure is different depending on linux vs windows, it's clearly not a robust way to check if call stack goes through the typing module

@Mandera
Copy link
Contributor Author

Mandera commented Jun 2, 2023

Perhaps something like inspect.getmodule(frame) and something from frame.f_globals to prevent false positive from a random package having a typing.py file

@Mandera
Copy link
Contributor Author

Mandera commented Jun 2, 2023

Ohh!! Can just do

from inspect import getmodule
import typing

...
if getmodule(frame) is typing:

Dynamic dunder support!
New ErrorPars dataclass to hold parameters.
Cleaned up file structure.
@Mandera Mandera merged commit 06bf562 into master Jun 2, 2023
1 check passed
@Mandera Mandera deleted the allow_typing_hacky branch June 2, 2023 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow typing from missing dependency
2 participants