Skip to content

Conversation

@MehrazRumman
Copy link

@MehrazRumman MehrazRumman commented Jan 5, 2026

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

Closes #10791

This PR updates the behavior of the W1514 (unspecified-encoding) warning to account for
changes introduced by PEP 686.

Starting with Python 3.15, UTF-8 becomes the default text encoding, making the absence of
an explicit encoding= argument safe and predictable. As a result, emitting W1514 by
default for Python 3.15+ produces unnecessary false positives.

What this PR does

  • Keeps W1514 enabled by default for Python versions < 3.15
  • Disables W1514 by default for Python >= 3.15
  • Preserves backward compatibility for older Python interpreters

This reduces noise for users targeting modern Python versions while maintaining safety
checks for older environments.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this !

Comment on lines 909 to 924
self.add_message(
"unspecified-encoding", node=node, confidence=confidence
)
if emit_unspecified_encoding:
self.add_message(
"unspecified-encoding", node=node, confidence=confidence
)

if encoding_arg:
encoding_arg = utils.safe_infer(encoding_arg)

if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
self.add_message(
"unspecified-encoding", node=node, confidence=confidence
)
if emit_unspecified_encoding:
self.add_message(
"unspecified-encoding", node=node, confidence=confidence
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd already have exited from the function at this point, right ?

It is better to specify an encoding when opening documents. Using the system
default implicitly can create problems on other operating systems. See
https://peps.python.org/pep-0597/
This message is only emitted when ``py-version`` is lower than 3.15.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation need to be added inside the code, as this file is generated.

Comment on lines 150 to 153
if sys.version_info < (3, 15):
assert mod_test._linter.is_message_enabled("unspecified-encoding")
else:
assert not mod_test._linter.is_message_enabled("unspecified-encoding")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the idea here ? Is this LLM suggested ? Because I don't see any code related to this in the implementation afaiu

Copy link
Author

@MehrazRumman MehrazRumman Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry this is not the final, I am moving it to draft, I took the initial idea from LLM, Thanks ! @Pierre-Sassoulas

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code backport maintenance/4.0.x labels Jan 5, 2026
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.0.5 milestone Jan 5, 2026
@Pierre-Sassoulas Pierre-Sassoulas changed the title Trying to fix issue #10791 Disable unspecified-encoding for py-version above Python 3.15 Jan 5, 2026
@MehrazRumman MehrazRumman marked this pull request as draft January 5, 2026 18:06
@MehrazRumman
Copy link
Author

Thanks for the fast review @Pierre-Sassoulas ! Once finished with the optimal version of the PR, I will request for re-review! Thanks again !

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.98%. Comparing base (4f6c241) to head (a8b96df).

Files with missing lines Patch % Lines
pylint/checkers/stdlib.py 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10800      +/-   ##
==========================================
- Coverage   95.98%   95.98%   -0.01%     
==========================================
  Files         176      176              
  Lines       19564    19566       +2     
==========================================
+ Hits        18779    18780       +1     
- Misses        785      786       +1     
Files with missing lines Coverage Δ
pylint/checkers/stdlib.py 96.02% <50.00%> (-0.31%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit a8b96df

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport maintenance/4.0.x False Positive 🦟 A message is emitted but nothing is wrong with the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disable by default W1514 unspecified-encoding starting Python 3.15

2 participants