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

F821 triggers when using non-ASCII characters #942

Closed
trag1c opened this issue Nov 28, 2022 · 16 comments
Closed

F821 triggers when using non-ASCII characters #942

trag1c opened this issue Nov 28, 2022 · 16 comments
Labels
bug Something isn't working

Comments

@trag1c
Copy link
Contributor

trag1c commented Nov 28, 2022

from time import time_ns

def time_µs() -> int:
	return time_ns() // 1000

def main() -> None:
	print(time_µs())

if __name__ == "__main__":
	main()
test.py:7:9: F821 Undefined name `time_μs`

(it's obviously fine with a name like time_us)

@charliermarsh charliermarsh added the bug Something isn't working label Nov 28, 2022
@charliermarsh
Copy link
Member

Fascinating.

@charliermarsh
Copy link
Member

Oddly I'm not seeing this error when running on my machine 🤔

@trag1c
Copy link
Contributor Author

trag1c commented Nov 30, 2022

Oddly I'm not seeing this error when running on my machine 🤔

Do you need any more details?

@charliermarsh
Copy link
Member

Could it make a difference if you uploaded the exact file, rather than pasting the snippet?

@trag1c
Copy link
Contributor Author

trag1c commented Nov 30, 2022

Could it make a difference if you uploaded the exact file, rather than pasting the snippet?

Unfortunately, I don't have the exact file anymore. I didn't actually run this snippet until now, and oddly it also seems to work for me in this case.

It complains about it in this example though:

def time_µs():
    ...

def main():
    time_μs()

@charliermarsh
Copy link
Member

Oh cool, that repros for me too. Thanks!

@charliermarsh
Copy link
Member

Really don't understand this one.

It seems to work fine if you indent with tabs, but not with spaces?

def time_µs() -> int:
	...

def main() -> None:
	time_µs()

@charliermarsh
Copy link
Member

charliermarsh commented Nov 30, 2022

Wait, no, that's wrong -- the tabs are irrelevant.

@charliermarsh
Copy link
Member

I think there's something strange in how the time_µs is written in the first example. Notice that my editor doesn't like it either:

Screen Shot 2022-11-29 at 9 23 43 PM

Screen Shot 2022-11-29 at 9 23 40 PM

@charliermarsh
Copy link
Member

Yeah, I think these are actually using different characters? In foo.py above, the first representation of time_us uses:

116
105
109
101
95
194
181
115

The second uses:

116
105
109
101
95
206
188
115

The difference is [206, 188] vs. [194, 181], which I guess represent slightly different characters?

string_utf8_lossy: μ
string_utf8_lossy: µ

@charliermarsh
Copy link
Member

So, I think this is correct?

@charliermarsh
Copy link
Member

Sigh, yes, the former ([206, 188]) is Greek Small Letter Mu, while the latter ([194, 181]) is Micro Sign. You can see that the UTF-8 Encoding hex digits match up.

@trag1c
Copy link
Contributor Author

trag1c commented Nov 30, 2022

Sorry for wasting your time, looks like it's VSCode that treats these two as the same character, e.g. when highlighting or using autocompletion (that's probably when it inserted a different character? 🤨).

Anyways great project! ❤️

@charliermarsh
Copy link
Member

Haha no, all good, I was totally stumped! I learned a bit about debugging this stuff anyway.

Thank you for the kind words :)

@ekzhang
Copy link

ekzhang commented Nov 30, 2022

(Off-topic) By the way, Rust has a built-in lint for this, just tried compiling the code in this playground.

image

@covracer
Copy link
Contributor

Hopefully #4430 will help prevent micro/mu mixups

I was also surprised by PEP 3131 edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants