0

In How do I type hint a filename in a function?, it was asked

What is a best way in Python to hint a filename, so that it's acceptable to pass anything into a function that you can open as a file?

at the time, @lxop wrote

I think what you are looking for is Structural Typing, which is not yet supported. It is proposed in PEP 544.

Given that Python 3.8+ has Structural Typing, how should we use Structural Typing hints for filenames?

4
  • N.B. @lxop mentioned (stackoverflow.com/questions/53418046/…) that they had not yet found an "official" use of Structural Typing for filenames, but this might have changed in the last ~18 months. It may be that this question does not yet have an answer.
    – kc9jud
    Jun 29, 2022 at 5:13
  • If you scroll down a bit in the thread @kc9jud linked, there is a excerpt from PEP 519: stackoverflow.com/a/61804884/14536215
    – Tzane
    Jun 29, 2022 at 5:52
  • @Tzane ah, I guess I misunderstood that -- the recommendation from PEP 519 still stands even with PEP 544?
    – kc9jud
    Jun 29, 2022 at 5:58
  • I would assume so. At least PEP 519 isn't mentioned in 544, but I admit I haven't read the whole thing, so I could be proven wrong
    – Tzane
    Jun 29, 2022 at 6:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.