You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unnecessary warning gets issued when constructing a SysFont with the default font explicitlyΒ #2643
/home/oddbookworm/Projects/pygame-ce/venv/lib/python3.11/site-packages/pygame/sysfont.py:492: UserWarning: The system font 'freesansbold.ttf' couldn't be found. Did you mean: 'freesansbold'? Using the default font instead.
warnings.warn(
I'm not sure if this is something we should fix at all?
The warning is raised because the sysfont code normally doesn't handle file extensions and just expects the font name. If we want the warning to go away we need to either
Implement a generic solution that handles every input by stripping an extension (if it has one)
specialcase freesansbold.ttf specifically, which I don't like the idea of doing
Hello, id like to be assigned to this please. I will build up some background information and either propose a PR or path forward around if this is indeed an issue or not.
Ive completed my initial review, and I believe the issue is more related to misunderstanding on how SysFont is intended to work due it be being a little different implementation than the base Font module.
I believe OP is intending to instantiate a SysFont object with defaults, but did not expect to recieve that warning since they did not appear to violate any expected usage. Unlike Font, there is no default SysFont overload without arguments so you do have to supply something even if there is no preference on font and size. This seems to be what OP is trying to do incorrectly.
Right now, there is some ambiguity of how this module works and how to utilize it correctly per the written documentation which may be causing the confusion. Some of my observations are as follows:
Its not clear that the pygame.font.get_default_font() function returns a name of font with extension
There is no explanation that the 'name' argument of SysFont(name, ...) should be supplied without extension
Maybe at a high level its not perfectly clear what the difference in modules is or why you would or would not use SysFont. OP trying to instantiate with defaults seems to indicate the SysFont use case is not coming across clearly to users. There is no dynamic behavior shown in OPs code that would necessitate usage of SysFont
Basically OPs usage here doesnt really make any sense if they are just going to use freesansbold as the font.
I think the simplest solution here is just to improve clarity of how to use the module per the following actions:
Clarify in documentation that 'name' should not include extensions. This pushes responsibility of understanding of how to use SysFont correctly to the user again since it is now clear they are not utilizing it as intended.
Add another warning for bad 'name' type or format, or update the current warning to include this info. The current warning just covers the case of name not found, but not bad name input.
Update get_default_font() documentation to also explain the name returned shall include extension. Again, more detail the user should be aware of to utilize this correctly.
I dont think there is any actions to take on default overload for SysFont since it would just duplicate Font(). Right now I think it makes sense that this does not happen since someone using the SysFont module should expect some more special behavior which is why they are not using Font(). Letting them duplicate Fon() defaults overload would just enable their misunderstanding and misusage of SysFont.
From a documentation perspective, I do think there could be greater clarity added to explaining why SysFont exists in the first place and difference between that and just using Font. I had to dig in a bit to the code to make sense of what the intention was of SysFont which the users of pygame should not really be expected to do if the documentation could just clarify. I think this could be opened as a separate issue, to be ruled on by the community yay or nay, so I will not address it here.
Let me know if my approach seems ok and I can start a PR.
Opened a PR to do 1 and 2. Left out 3 since think the user should be responsible to determine format of value if needed. The docs state the font name is returned which should logically indicate full file name with extension
Activity
Starbuck5 commentedon Jan 1, 2024
Duplicate of #2319, fixed in #2543
Starbuck5 commentedon Jan 1, 2024
Nevermind, this still persists when asking for "freesansbold.ttf" instead of "freesansbold", as the code above does through the get_default_font call.
ankith26 commentedon May 21, 2024
I'm not sure if this is something we should fix at all?
The warning is raised because the
sysfontcode normally doesn't handle file extensions and just expects the font name. If we want the warning to go away we need to eitherfreesansbold.ttfspecifically, which I don't like the idea of doingActualPanda commentedon Oct 9, 2024
Could it also be an option to have a
pygame.font.get_default_sysfont()function instead?mv805 commentedon Mar 1, 2025
Hello, id like to be assigned to this please. I will build up some background information and either propose a PR or path forward around if this is indeed an issue or not.
Starbuck5 commentedon Mar 1, 2025
Sure.
mv805 commentedon Mar 3, 2025
Ive completed my initial review, and I believe the issue is more related to misunderstanding on how SysFont is intended to work due it be being a little different implementation than the base Font module.
I believe OP is intending to instantiate a SysFont object with defaults, but did not expect to recieve that warning since they did not appear to violate any expected usage. Unlike Font, there is no default SysFont overload without arguments so you do have to supply something even if there is no preference on font and size. This seems to be what OP is trying to do incorrectly.
Right now, there is some ambiguity of how this module works and how to utilize it correctly per the written documentation which may be causing the confusion. Some of my observations are as follows:
Basically OPs usage here doesnt really make any sense if they are just going to use freesansbold as the font.
I think the simplest solution here is just to improve clarity of how to use the module per the following actions:
I dont think there is any actions to take on default overload for SysFont since it would just duplicate Font(). Right now I think it makes sense that this does not happen since someone using the SysFont module should expect some more special behavior which is why they are not using Font(). Letting them duplicate Fon() defaults overload would just enable their misunderstanding and misusage of SysFont.
From a documentation perspective, I do think there could be greater clarity added to explaining why SysFont exists in the first place and difference between that and just using Font. I had to dig in a bit to the code to make sense of what the intention was of SysFont which the users of pygame should not really be expected to do if the documentation could just clarify. I think this could be opened as a separate issue, to be ruled on by the community yay or nay, so I will not address it here.
Let me know if my approach seems ok and I can start a PR.
mv805 commentedon Mar 7, 2025
Opened a PR to do 1 and 2. Left out 3 since think the user should be responsible to determine format of value if needed. The docs state the font name is returned which should logically indicate full file name with extension
Improve SysFont documentation and add font verification warning. Closes