Title: gh-93417: Update `mimetypes.init()` doc to match the code by bebound · Pull Request #141393 · python/cpython · GitHub
Open Graph Title: gh-93417: Update `mimetypes.init()` doc to match the code by bebound · Pull Request #141393 · python/cpython
X Title: gh-93417: Update `mimetypes.init()` doc to match the code by bebound · Pull Request #141393 · python/cpython
Description: This PR is a supplement of #3062. Change the doc to match the current behavior. After #3062, the init(files) function still loads the knownfiles when files=[]: cpython/Lib/mimetypes.py Lines 405 to 433 in 9b0179f def init(files=None): global suffix_map, types_map, encodings_map, common_types global inited, _db inited = True # so that MimeTypes.__init__() doesn't call us again if files is None or _db is None: db = MimeTypes() # Quick return if not supported db.read_windows_registry() if files is None: files = knownfiles else: files = knownfiles + list(files) else: db = _db # Lazy import to improve module import time import os for file in files: if os.path.isfile(file): db.read(file) encodings_map = db.encodings_map suffix_map = db.suffix_map types_map = db.types_map[True] common_types = db.types_map[False] # Make the DB a global variable now that it is fully initialized _db = db Specifying an empty list for files will prevent the system defaults from being applied: only the well-known values will be present from a built-in list. --https://docs.python.org/3/library/mimetypes.html#mimetypes.init The above doc reflects on the old code logic: cpython/Lib/mimetypes.py Lines 341 to 358 in 27a8564 def init(files=None): global suffix_map, types_map, encodings_map, common_types global inited, _db inited = True # so that MimeTypes.__init__() doesn't call us again db = MimeTypes() if files is None: if _winreg: db.read_windows_registry() files = knownfiles for file in files: if os.path.isfile(file): db.read(file) encodings_map = db.encodings_map suffix_map = db.suffix_map types_map = db.types_map[True] common_types = db.types_map[False] # Make the DB a global variable now that it is fully initialized _db = db PS: I did not walk through the https://bugs.python.org/issue4963 to see whether the init(files=[]) behavior change is necessary. (Well, reverting to Python 3.7's behavior is also unlikely?) For now, we should at least update the documentation. Issue: gh-93417 📚 Documentation preview 📚: https://cpython-previews--141393.org.readthedocs.build/
Open Graph Description: This PR is a supplement of #3062. Change the doc to match the current behavior. After #3062, the init(files) function still loads the knownfiles when files=[]: cpython/Lib/mimetypes....
X Description: This PR is a supplement of #3062. Change the doc to match the current behavior. After #3062, the init(files) function still loads the knownfiles when files=[]: cpython/Lib/mimetypes....
Opengraph URL: https://github.com/python/cpython/pull/141393
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:74e0bace-e59b-9822-3cdf-3d4f6c137c2b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CCB0:19E603:1DD696:271193:6AED1727 |
| html-safe-nonce | e4fe3e7e39870b32dc5b0c2d227070a8379d6bb3da9cbefe97a6d26bc770819e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQ0IwOjE5RTYwMzoxREQ2OTY6MjcxMTkzOjZBRUQxNzI3IiwidmlzaXRvcl9pZCI6IjU3MzM3OTYxNzI0NzU5OTU5NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 07f584e7b4e15369bc8e54de813241306e9c1d6a584631e30331350b85bd6b2b |
| hovercard-subject-tag | pull_request:2998201431 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/141393/files |
| twitter:image | https://avatars.githubusercontent.com/u/2227874?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/2227874?s=400&v=4 |
| og:image:alt | This PR is a supplement of #3062. Change the doc to match the current behavior. After #3062, the init(files) function still loads the knownfiles when files=[]: cpython/Lib/mimetypes.... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 120085d0bcec1f427e3ab45302c8b95f873d26ad21984dc86d62ab2c10158f41 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e12fd03aa775dceadc5a793c3a0791e43ca256bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width