GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-104265 Disallow instantiation of `_csv.Reader` and `_csv.Writer` by chgnrdv · Pull Request #104266 · python/cpython

Conversation

@chgnrdv

@chgnrdv chgnrdv commented May 7, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #104265

Set Py_TPFLAGS_DISALLOW_INSTANTIATION and unset Py_TPFLAGS_BASETYPE flags on Reader and Writer types to prevent their instantiation and subtyping

  • Issue: _csv Reader and Writer types shouldn't be directly instantiable #104265

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chgnrdv
Disallow instantiation and subtyping of _csv.Reader and `_csv.Write…
ae69f9b
…r` types

Set `Py_TPFLAGS_DISALLOW_INSTANTIATION` and unset `Py_TPFLAGS_BASETYPE` flags on `Reader` and `Writer` types to prevent their instantiation and subtyping
@bedevere-bot bedevere-bot added the awaiting review label May 7, 2023
@chgnrdv chgnrdv changed the title Disallow instantiation and subtyping of _csv.Reader and _csv.Writer gh-104265 Disallow instantiation and subtyping of _csv.Reader and _csv.Writer May 7, 2023
@bedevere-bot bedevere-bot mentioned this pull request May 7, 2023
_csv Reader and Writer types shouldn't be directly instantiable #104265
Closed
@corona10
corona10 requested a review from erlend-aasland May 7, 2023 13:34
@erlend-aasland

erlend-aasland commented May 7, 2023

Copy link
Copy Markdown
Contributor

Thanks! This needs a NEWS entry, preferrably with a reference to when the bug was introduced. I think this should be backported through to 3.10.

chgnrdv and Eclips4 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented May 7, 2023

Copy link
Copy Markdown
Contributor

Also, please add tests. There's a dedicated test.support helper for this. Grep through the code base to find it and see how it's used.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chgnrdv

chgnrdv commented May 7, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@erlend-aasland, are you talking about assert_python_ok? Can't we just check if TypeError with proper message is raised on attempt to create instance/subtype?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chgnrdv
added test
7d1fcd8
@erlend-aasland

erlend-aasland commented May 7, 2023

Copy link
Copy Markdown
Contributor

There's a disallow_instantiation helper in test.support.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chgnrdv
changed tests to use check_disallow_instantiation, separated tests
aa34fae
@erlend-aasland erlend-aasland added the needs backport to 3.11 only security fixes label May 7, 2023
@erlend-aasland

erlend-aasland commented May 7, 2023

Copy link
Copy Markdown
Contributor

Thanks! This needs a NEWS entry, preferrably with a reference to when the bug was introduced. I think this should be backported through to 3.10.

Ah, 3.10 is in security fix mode, so we can only backport to 3.11.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented May 7, 2023

Copy link
Copy Markdown
Contributor

Some history, the original issue for applying PEP-384 to the _csv extension module:

  • PEP 384 Refactoring applied to _csv module #59140 (bpo-14935)
  • bpo-14935: Remove static state from the _csv module #23224

A later (duplicate issue); the linked PRs were closed and incorporated into gh-23224

  • Apply PEP384 to _csv module #78714 (bpo-34533)
  • bpo-34533: Apply PEP384 to _csv module #8977
  • bpo-34533: Remove all static state from _csv module #16078

As you can see, both the Writer and the Reader class had Py_TPFLAGS_BASETYPE when they were converted from static to heap types. Removing that flag is a backwards incompatible change, as third-party software may depend on that behaviour. Please revert that particular change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland erlend-aasland changed the title gh-104265 Disallow instantiation and subtyping of _csv.Reader and _csv.Writer gh-104265 Disallow instantiation of _csv.Reader and _csv.Writer May 7, 2023
erlend-aasland
erlend-aasland requested changes May 7, 2023
View reviewed changes

@erlend-aasland erlend-aasland left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Changes requested:

  • Revert Py_TPFLAGS_BASETYPE changes
  • Add NEWS entry

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting review labels May 7, 2023
@bedevere-bot

bedevere-bot commented May 7, 2023

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chgnrdv
reverted Py_TPFLAGS_BASETYPE flag deletion, removed corresponding tests
6c45ff8
@chgnrdv

chgnrdv commented May 7, 2023

Copy link
Copy Markdown
Contributor Author

Looks like 6a02b38 from #23224 introduced this issue. How can I reflect this in NEWS entry text? Should I specify an issue number?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@blurb-it
📜🤖 Added by blurb_it.
7d9ec2a
@erlend-aasland

erlend-aasland commented May 7, 2023

Copy link
Copy Markdown
Contributor

Looks like 6a02b38 from #23224 introduced this issue. How can I reflect this in NEWS entry text? Should I specify an issue number?

Indeed it did.

You can reference GitHub issues/PRs with the :gh: Sphinx directive. Here's a suggestion to a NEWS entry:

Prevent possible crash by disallow instantiation of the :class:`!_csv.Reader`
and :class:`!_csv.Writer` types. The regression was introduced by :gh:`23224`
in Python 3.10. Patch by <your-name-here>.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chgnrdv added 3 commits May 7, 2023 19:24
@chgnrdv
Update 2023-05-07-16-13-07.gh-issue-104265.fU60bZ.rst
19bddd0
@chgnrdv
Update 2023-05-07-16-13-07.gh-issue-104265.fU60bZ.rst
b3f4a65
@chgnrdv
Update 2023-05-07-16-13-07.gh-issue-104265.fU60bZ.rst
a022e91
@chgnrdv
chgnrdv requested a review from erlend-aasland May 7, 2023 16:49
blurb-it Bot and others added 2 commits May 7, 2023 19:56
@blurb-it
📜🤖 Added by blurb_it.
52aacfd
@chgnrdv
Delete 2023-05-07-16-13-07.gh-issue-104265.fU60bZ.rst
d31d214
@chgnrdv

chgnrdv commented May 7, 2023

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels May 7, 2023
@bedevere-bot

bedevere-bot commented May 7, 2023

Copy link
Copy Markdown

Thanks for making the requested changes!

@erlend-aasland: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland reviewed May 7, 2023
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2023-05-07-19-56-45.gh-issue-104265.fVblry.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland
Update Misc/NEWS.d/next/Library/2023-05-07-19-56-45.gh-issue-104265.f…
2804744
…Vblry.rst
erlend-aasland
erlend-aasland reviewed May 7, 2023
View reviewed changes
Comment thread Lib/test/test_csv.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

chgnrdv added 2 commits May 7, 2023 23:49
@chgnrdv
applied suggestion by erlend-aasland
8255467
@chgnrdv
Merge branch '_csv-make-Reader-Writer-types-non-instantiable' of gith…
73609a8
…ub.com:chgnrdv/cpython into _csv-make-Reader-Writer-types-non-instantiable
erlend-aasland
erlend-aasland approved these changes May 7, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting change review labels May 7, 2023
@erlend-aasland
erlend-aasland enabled auto-merge (squash) May 7, 2023 21:14
@erlend-aasland

erlend-aasland commented May 7, 2023

Copy link
Copy Markdown
Contributor

Thank you so much for the report and bugfix, Radislav; good job!

chgnrdv reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland
erlend-aasland merged commit 06c2a48 into python:main May 7, 2023
@miss-islington

miss-islington commented May 7, 2023

Copy link
Copy Markdown
Contributor

Thanks @chgnrdv for the PR, and @erlend-aasland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label May 7, 2023
@bedevere-bot

bedevere-bot commented May 7, 2023

Copy link
Copy Markdown

GH-104278 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 7, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 7, 2023
@chgnrdv @miss-islington
pythongh-104265 Disallow instantiation of _csv.Reader and `_csv.Wri…
0a7ec7e
…ter` (pythonGH-104266)

(cherry picked from commit 06c2a48)

Co-authored-by: chgnrdv <[email protected]>
@chgnrdv

chgnrdv commented May 7, 2023

Copy link
Copy Markdown
Contributor Author

@erlend-aasland, thank you for your patient review :)

erlend-aasland reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303 pushed a commit that referenced this pull request May 8, 2023
@miss-islington @chgnrdv
[3.11] gh-104265 Disallow instantiation of _csv.Reader and `_csv.Wr…
065e2ae
…iter` (GH-104266) (#104278)

gh-104265 Disallow instantiation of `_csv.Reader` and `_csv.Writer` (GH-104266)
(cherry picked from commit 06c2a48)

Co-authored-by: chgnrdv <[email protected]>
jbower-fb pushed a commit to jbower-fb/cpython that referenced this pull request May 8, 2023
@chgnrdv @jbower-fb
pythongh-104265 Disallow instantiation of _csv.Reader and `_csv.Wri…
8e76e2d
…ter` (python#104266)
carljm added a commit to carljm/cpython that referenced this pull request May 9, 2023
@carljm
Merge branch 'main' into inlinecomp2
76077cd
* main: (47 commits)
  pythongh-97696 Remove unnecessary check for eager_start kwarg (python#104188)
  pythonGH-104308: socket.getnameinfo should release the GIL (python#104307)
  pythongh-104310: Add importlib.util.allowing_all_extensions() (pythongh-104311)
  pythongh-99113: A Per-Interpreter GIL! (pythongh-104210)
  pythonGH-104284: Fix documentation gettext build (python#104296)
  pythongh-89550: Buffer GzipFile.write to reduce execution time by ~15% (python#101251)
  pythongh-104223: Fix issues with inheriting from buffer classes (python#104227)
  pythongh-99108: fix typo in Modules/Setup (python#104293)
  pythonGH-104145: Use fully-qualified cross reference types for the bisect module (python#104172)
  pythongh-103193: Improve `getattr_static` test coverage (python#104286)
  Trim trailing whitespace and test on CI (python#104275)
  pythongh-102500: Remove mention of bytes shorthand (python#104281)
  pythongh-97696: Improve and fix documentation for asyncio eager tasks (python#104256)
  pythongh-99108: Replace SHA3 implementation HACL* version (python#103597)
  pythongh-104273: Remove redundant len() calls in argparse function (python#104274)
  pythongh-64660: Don't hardcode Argument Clinic return converter result variable name (python#104200)
  pythongh-104265 Disallow instantiation of `_csv.Reader` and `_csv.Writer` (python#104266)
  pythonGH-102613: Improve performance of `pathlib.Path.rglob()` (pythonGH-104244)
  pythongh-103650: Fix perf maps address format (python#103651)
  pythonGH-89812: Churn `pathlib.Path` methods (pythonGH-104243)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@erlend-aasland erlend-aasland erlend-aasland approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

_csv Reader and Writer types shouldn't be directly instantiable

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@chgnrdv @erlend-aasland @bedevere-bot @miss-islington
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.