4

I found *.py{} in a .gitignore file and I am wondering what this extension is.

Found here.

And here.

PS. The git commit mentioned pypy.

Hielke Walinga
  • 2,677
  • 1
  • 17
  • 30
  • 3
    It says right above it that it is a compiled python file extension – DetectivePikachu Nov 07 '19 at 16:27
  • 4
    `.py{}` is not a standard extension, though. Either this is an error in the file, or their build process does something really unusual. – chepner Nov 07 '19 at 16:31
  • 1
    @DetectivePikachu There is .pyc, .pyo, and .pyc for compiled Python. See also https://stackoverflow.com/questions/8822335/what-do-the-python-file-extensions-pyc-pyd-pyo-stand-for However, I can find nowhere information about .py{}. – Hielke Walinga Nov 07 '19 at 16:31
  • 1
    I could also find it here: https://codeberg.org/biotite-dev/biotite/src/commit/1882a661f00f3368b6b3dc71bb6eb33c5be0003d/.gitignore – Hielke Walinga Nov 07 '19 at 16:32
  • 2
    The comment of the commit that added that ignore rule states "Ignore *.py{} and *.py-e files (from PyPy?)" – Aaron Nov 07 '19 at 16:33
  • 2
    My best guess was this was supposed to be a brace expansion, but for some reason was left empty. Or they have some bizarre obscure or custom testing suite that makes these extensions. I dunno. You'd have to ask the authors. The git blame mentions PyPy, so maybe they were writing some kind of custom interpreter? Its odd in any case – DetectivePikachu Nov 07 '19 at 16:35
  • 3
    Git's ignore files don't do any sort of brace expansion, so `*.py{c,o}` would be taken literally, rather than being a shortcut for `*.pyc` and `*.pyo`. – chepner Nov 07 '19 at 16:40
  • 2
    The number of "what does X do?" questions we have in this knowledgebase, where X is completely useless code that was introduced as a bug in some random 3rd-party library... – Charles Duffy Nov 07 '19 at 17:23
  • 1
    ...indeed, I'd argue that that's one of the places where there's value in enforcing our rules that questions must be about "a problem you actually face", as opposed to a point of curiosity or trivia. – Charles Duffy Nov 07 '19 at 17:24
  • @CharlesDuffy Well, this question actually came from a problem I was facing when using ripgrep on the Biopython repo. Apparently this specific pattern is interpreted by the globbing system of ripgrep causing all *.py files to be ignored. That's a ripgrep bug. Funny how two seemingly minor bugs made me completely lost on the real problem I was dealing with with the actual Python code. Luckily, there was still good ol' grep -R, to bring me to the right file. – Hielke Walinga Nov 07 '19 at 18:22

1 Answers1

2

It isn't a common file extension, but the braces {} are used in globs (like regex) for pattern recognition. From this link on globs, it is

Bash style brace expansions. This is applied to patterns before anything else.

Though it's left empty so I'm not sure that it does anything of use in this case.

ufoxDan
  • 609
  • 4
  • 13
  • 2
    What does that link have to do with `.gitignore` files? – chepner Nov 07 '19 at 16:41
  • The point is whomever wrote this gitignore appears to have been attempting to do a glob. Though in your comment you mention that git doesn't do expansion so to answer the OP's question: it *isn't* a file extension – ufoxDan Nov 07 '19 at 16:46
  • 1
    You are *assuming* that's what they're trying, and only in that Python library are globs and brace expansions lumped into the same category. – chepner Nov 07 '19 at 17:08
  • It *could* be a file extension. Create a file named `foo.py{}`, and per that pattern, Git will ignore it. – chepner Nov 07 '19 at 17:09
  • Yes it can be a file extension, but it's not some common file extension which seems to be what OP was asking about - so yes I should have worded my response more carefully. As @DetectivePikachu pointed out, it could be for some strange test suite (or just a mistake), but it's not some *common* file extension. – ufoxDan Nov 07 '19 at 17:16